﻿<%@page language="abap"%>
﻿<!DOCTYPE HTML>
<html>
<head>
    <title>BI Apps - Edit Variable View</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="Stylesheet" type="text/css" href="../theme/css/style_reset.css" />
    <link rel="Stylesheet" type="text/css" href="../theme/css/style_admin_tabs.css" />
    <link rel="Stylesheet" type="text/css" href="../theme/css/button_content.css" />
    <link rel="Stylesheet" type="text/css" href="../theme/css/form_content.css" />
    <script type="text/JavaScript" src="../api/js/jquery-1.8.3.js"></script>
    <script type='text/JavaScript' src='../../zbw_reporting/scripts/framework_include.js'></script>

    <script type="text/javascript">
        // otaism2a: 28,1,2014 to reduce multiple BOI.js while loading
        var BOI = parent.BOI;
        var view = { APP_ID: parent.app_id, VIEW_ID: "", VIEW_NAME: "", URL: "" };
        var method_name = "CREATE";

        $(function () {
            $('#submit').live('click', function () {
                request();
            });
            $("#reset").live('click', function () {
                window.location.href = window.location.href;
            });

            //bind input change events for view info
            $('form li input[name], form li select[name]').live('change', function () {
                view[$(this).attr('name')] = $(this).val();
            });

            BOI.BOIData.list.getUserApps(function (data) {
                $(data).find('APP').each(function () {
                    $('#APP_ID').append('<option value="' + $(this).text() + '">' + $(this).text() + '</option>');
                });

                if (parent.current_view) {
                    view.VIEW_ID = parent.current_view.VIEW_ID;
                    view.APP_ID = parent.current_view.APP_ID;
                    $('#APP_ID').val(view.APP_ID);
                }

                if (view.VIEW_ID && view.VIEW_ID != "")
                    BOI.BOIData.read.getView(view.APP_ID, view.VIEW_ID, function (data) {
                        method_name = "UPDATE";
                        $(data).find('VIEW').children().each(function () {
                            var tag = this.tagName;
                            view[tag] = $(this).text();
                            $('#' + tag).val(view[tag]);
                        });
                        $('#VIEW_ID').attr('readonly', 'readonly');
                        $('#APP_ID').attr("disabled",true);
                    });
            });
        });

        function request() {
            var record, class_name, req, param, done = 0;
            record = new BOI.BOIData.Record();
            class_name = "ZCL_MYBW_VAR_VIEW";

            for (var i in view) {
                if (i) {
                    param = new BOI.BOIData.Parameter();
                    param.name = i;
                    param.values = view[i] == null ? [""] : [view[i]];
                    record.parameters.push(param);
                }
            }
            req = BOI.BOIData.request.prepare(class_name, method_name, [record]);

            BOI.BOIData.request.perform(req, 'text', 'POST', function (data) {
               // alert($(data).find('MESSAGE').text());
                BOI.BOILib.Util.log($(data).find('MESSAGE').text(),true);
                parent.current_view = view;
                parent.refreshViews();
                //parent.refresh(undefined, method_name);
            });
        }
    </script>

</head>
<body>
<div class="tab-frame bi_admin_view_editor">
    <form>
        <h2>BI Apps - Edit Variable View</h2>
        <ul>
            <li>
                <label for="APP_ID">APP ID:</label><select id="APP_ID" name="APP_ID"></select></li>
            <li>
                <label for="VIEW_ID">View ID:</label><input id="VIEW_ID" name="VIEW_ID" type="text" /></li>
            <li>
                <label for="VIEW_NAME">View Name:</label><input id="VIEW_NAME" name="VIEW_NAME" type="text" /></li>
            <li>

        <label for="URL">Component URL:</label><input id="URL" name="URL" type="text" /></li>
            <li>
                <a id="submit" class="button-content-YW" href="#"><span>Save</span></a></li>
        </ul>
    </form>
</div>
</body>
</html>